﻿package mortal.game.resource.tableConfig
{
    import Message.DB.Tables.*;
    import com.gengine.resource.*;
    import flash.utils.*;
    import mortal.game.view.common.*;

    public class GuildDefenseConfig extends Object
    {
        private static var _instance:GuildDefenseConfig;
        private static var _towerDic:Dictionary = new Dictionary();
        private static var _guildDefenseCopyArr:Array = new Array();

        public function GuildDefenseConfig()
        {
            if (_instance != null)
            {
                throw new Error(" GuildDefenceConfig 单例 ");
            }
            this.init();
            return;
        }// end function

        private function init() : void
        {
            var _loc_1:* = ConfigManager.instance.getJSONByFileName("t_guild_defence_tower.json");
            this.write(_loc_1);
            _loc_1 = ConfigManager.instance.getJSONByFileName("t_guild_defense_copy.json");
            this.writeBaseValue(_loc_1);
            return;
        }// end function

        private function write(param1:Object) : void
        {
            var _loc_2:TGuildDefenceTower = null;
            var _loc_3:Object = null;
            for each (_loc_3 in param1)
            {
                
                _loc_2 = new TGuildDefenceTower();
                ClassTypesUtil.copyValue(_loc_2, _loc_3);
                _towerDic[_loc_2.type + "_" + _loc_2.level] = _loc_2;
            }
            return;
        }// end function

        private function writeBaseValue(param1:Object) : void
        {
            var _loc_2:TGuildDefenseCopy = null;
            var _loc_3:Object = null;
            for each (_loc_3 in param1)
            {
                
                _loc_2 = new TGuildDefenseCopy();
                ClassTypesUtil.copyValue(_loc_2, _loc_3);
                _guildDefenseCopyArr.push(_loc_2);
            }
            return;
        }// end function

        public function getTowerInfoByTypeAndLevel(param1:int, param2:int) : TGuildDefenceTower
        {
            return _towerDic[param1 + "_" + param2];
        }// end function

        public function getCopyDefenseByLevel(param1:int) : TGuildDefenseCopy
        {
            var _loc_2:TGuildDefenseCopy = null;
            var _loc_3:TGuildDefenseCopy = null;
            for each (_loc_3 in _guildDefenseCopyArr)
            {
                
                if (_loc_3.level == param1)
                {
                    _loc_2 = _loc_3;
                    break;
                }
            }
            return _loc_2;
        }// end function

        public function get guildDefenseArr() : Array
        {
            return _guildDefenseCopyArr;
        }// end function

        public static function get instance() : GuildDefenseConfig
        {
            if (_instance == null)
            {
                _instance = new GuildDefenseConfig;
            }
            return _instance;
        }// end function

    }
}
